//
//  SMHFriendView.swift
//  SMHCommerce
//
//  Created by lvzhao on 2020/6/6.
//  Copyright © 2020 lvzhao. All rights reserved.
//

import UIKit

class SMHFriendView: LZBaseView,UITableViewDelegate,UITableViewDataSource {

    

    var viewModel = SMHFriendViewModel()
    override init(viewModel: LZBaseViewModel) {
        super.init(viewModel: viewModel)
        self.viewModel = viewModel as! SMHFriendViewModel
        setupUI()
        
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    //MARK:setupUI
    func setupUI() {
        addSubview(self.tableView)
        self.tableView.snp.makeConstraints { (make) in
            make.top.equalTo(0.5)
            make.left.right.bottom.equalTo(0)
        }
        
        let headView = SMHFriendHeadView.init(viewModel: self.viewModel)
        headView.frame = CGRect(x: 0, y: 0, width: kScreenWidth, height: 95)
        self.tableView.tableHeaderView = headView
        
    }
    
    //MARK:UITableViewDataSource
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        90
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let friendCell = tableView.dequeueReusableCell(withIdentifier: "SMHFriendCell", for: indexPath) as! SMHFriendCell
        friendCell.modelObject = nil
        return friendCell
    }
    
    //MARK:UITableViewDelegate
    func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        let sectionView = SMHFriendSectionView.init(viewModel: self.viewModel)
        sectionView.backgroundColor = UIColor.white
        sectionView.frame = CGRect(x: 0, y: 0, width: kScreenWidth, height: 45)
        return sectionView
    }
    
    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return 45;
    }
    
    
    
    lazy var tableView : LZBaseTableView = {
        let tableView = LZBaseTableView.init(frame: CGRect.zero, style: .plain)
        tableView.delegate = self
        tableView.dataSource = self
        tableView.register(SMHFriendCell.self, forCellReuseIdentifier: "SMHFriendCell")
        tableView.rowHeight = 55
        return tableView
    }()

}
